package jmu.cyxwcy.librarymanagement.controller;


import jmu.cyxwcy.librarymanagement.pojo.ReaderCategories;
import jmu.cyxwcy.librarymanagement.pojo.Result;
import jmu.cyxwcy.librarymanagement.service.IReaderCategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2024-06-24
 */
@RestController
@RequestMapping("/reader-categories")
public class ReaderCategoriesController {
    @Autowired
    private IReaderCategoriesService iReaderCategoriesService;
    //    读者类别
    @PostMapping("/add")
    public Result add(@RequestBody ReaderCategories readerCategories){
        iReaderCategoriesService.save(readerCategories);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody ReaderCategories readerCategories){
        iReaderCategoriesService.updateById(readerCategories);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result delete(Integer categoryId){
        iReaderCategoriesService.removeById(categoryId);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<ReaderCategories>> getAllCategories() {
        List<ReaderCategories> categories = iReaderCategoriesService.list();
        return Result.success(categories);
    }
}
